/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import java.util.*;
import javax.persistence.Query;

/**
 *
 * @author shinji
 */
@Stateless
public class StateFacade extends AbstractFacade<State> {
    @PersistenceContext(unitName = "Matrimony-ejbPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public StateFacade() {
        super(State.class);
    }
    
    public List<State> getState_Country(Country c){
        try {
            Query q = this.em.createQuery("select s from State s where s.iDCountry = :IDCountry");
            q.setParameter("IDCountry", c);
            
            return q.getResultList();
        } catch (Exception e) {
            return null;
        }
    }
    
    public List<State> getStateByCountryId(int country_ID){
        try {
            Query q = this.em.createQuery("select s from State s where s.iDCountry.id = :IDCountry");
            q.setParameter("IDCountry", country_ID);
            
            return q.getResultList();
        } catch (Exception e) {
            return null;
        }
    }
}
